{extend name='public/base' /}
{block name="css"}

{/block}
{block name="content"}

<div class="ibox xiaoshi">
    <div class="ibox-content">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form class="form-inline" id="user-form">
                    <div class="select-list">
                        <ul>

                            <li class="select-selectpicker">
                                用户：
                                <select name="user_id" class="selectpicker" data-none-selected-text="请选择">
                                    <option value="">所有</option>
                                    {$user|make_option='','nickname','id'}
                                </select>
                            </li>

                            {:li_select(['1'=>'未审核','2'=>'已审核'],'是否审核','status')}

                            {:li_select(['1'=>'未通过','2'=>'通过'],'是否通过审核','is_show')}

                            {:li_time()}

                            {:li_search()}

                        </ul>
                    </div>
                </form>
            </div>

        </div>
    </div>
</div>

<div class="row">
    <div class="col-sm-12">
        <div class="ibox">
            <div class="ibox-content">
                <div class="btn-group-sm" id="toolbar" role="group">
                    <a class="btn btn-success  btn-rounded multiple {:node('article.ArticleComment/check')}" onclick="check(1)">
                        <i class="fa fa-check"></i> 审核通过
                    </a>
                    <a class="btn btn-info  btn-rounded multiple {:node('article.ArticleComment/check')}" onclick="check(0)">
                        <i class="fa fa-remove"></i> 审核不通过
                    </a>

                    <a class="btn btn-danger btn-rounded multiple " onclick="$.form.removeAll()">
                        <i class="fa fa-remove"></i> 删除
                    </a>
                    <a class="btn btn-warning btn-rounded" onclick="$.table.exportExcel()">
                        <i class="fa fa-download"></i> 导出
                    </a>
                </div>
                <div class="table-striped">
                    <table id="bootstrap-table" ></table>
                </div>
            </div>
        </div>
    </div>
</div>

{/block}

{block name="js"} <!--js处理区-->

<script>
    $(function() {
        var options = {
            url: "{:url('index')}",
            deleteUrl:  "{:url('del')}?id={id}", //删除链接
            exportUrl:  "{:url('export')}",  //导出
            updateUrl: "{:url('edit')}?id={id}", //编辑
            addUrl:    "", //添加
            detailUrl:  "/detailUrl",    //详细
            sortName: "id",
            sortOrder: "desc",
            modalName: "文章评论",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: 'ID'
                },
                {
                    field: 'title',
                    title: '所属文章'
                },
                {
                    field: 'title_show',
                    title: '用户名'
                },
                {
                    field: 'content',
                    title: '评论内容',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value,100,'open');
                    }
                },
                {
                    field: 'status',
                    title: '是否审核',
                    align: 'center',
                    formatter: function(value, row, index) {
                        if (value == 0) {
                            return '<span class="badge badge-danger">未审核</span>';
                        } else{
                            return '<span class="badge badge-info">已审核</span>';
                        }
                    }
                },
                {
                    field: 'ip',
                    title: 'IP'
                },
                {
                    field: 'is_show',
                    title: '是否通过审核',
                    align: 'center',
                    formatter: function(value, row, index) {
                        if (value == 0) {
                            return '<span class="badge badge-warning">否</span>';
                        } else{
                            return '<span class="badge badge-info">是</span>';
                        }
                    }
                },
                {
                    field: 'browser',
                    title: '浏览器'
                },
                {
                    field: 'os',
                    title: '系统'
                },
                {
                    field: 'create_time',
                    title: '评论时间',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return edit_del(row);
                    }

                }]
        };
        $.table.init(options);
    });

    function edit_del(row) {
        var actions = [];
        actions.push('<a class="btn btn-xs btn-success  {:node(\'article.ArticleComment/edit\')}" data-original-title="编辑" data-toggle="tooltip" onclick="$.form.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i></a>');
        actions.push('<a class="btn btn-danger btn-xs {:node(\'article.ArticleComment/del\')}" data-original-title="删除" data-toggle="tooltip" onclick="$.form.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i></a>');
        return actions;
    }


    function check(type) {
        table.set();
        var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        var url="{:url('check')}";
        var ids=rows.join();
        if($.isArray(ids)) {
            ids = ids.join(',');
        }
        if ($.common.isEmpty(ids)) {
            $.models.toastr_error("没选择任何数据");return ;
        }
       if (type==1){
           msgs="确定审核通过选择的评论？";
       }else {
           msgs="确定审核不通过选择的评论？";
       }
        layer.confirm(msgs,{ icon: 3, title: "提示", anim: 1}, function(index){
            layer.close(index);
            $.ajax({
                beforeSend:function(){
                },
                url: url,
                type: "POST",
                async: true,
                dataType: "json",
                data:{
                    ids: ids,
                    is_show:type
                },
                error: function(error) {
                    $.models.toastr_error("服务器错误或超时");
                    return false;
                },
                success: function(data) {
                    if (data.code==1) {
                        $.models.toastr_success(data.msg,function () {
                            setTimeout(function(){
                                $.table.refresh();
                            },800);
                        });
                    }else{
                        $.models.toastr_error(data.msg,function () {
                            setTimeout(function(){
                                $.table.refresh();
                            },800);
                        });
                    }
                },
                complete:function(){
                }
            });
        });
    }




</script>

{/block}
